package com.fpj.sat.vehicle_administrator.util;

import javax.swing.table.AbstractTableModel;

public class RegistroModel extends AbstractTableModel{

	private static final long serialVersionUID = 970526169774904224L;

	private String[] columnNames = new String[0];
	private Object[][] data = new Object[0][0];
	
	public RegistroModel(String[] columnNames, int rowCount) {
		this.columnNames = columnNames;
		setData(new Object[rowCount][getColumnCount()]);
	}
	public int getColumnCount() {
		return columnNames.length;
	}
	public int getRowCount() {
		return data.length;
	}
	public String getColumnName(int col) {
		return columnNames[col];
	}
	public Object getValueAt(int row, int col) {
		return data[row][col];
	}
	public Object[] getValueAt(int row) {
		return data[row];
	}
	public Class<?> getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}
	public void setValueAt(Object value, int row, int col) {
		data[row][col] = value;
		fireTableCellUpdated(row, col);
	}
	public void setData(Object[][] data) {
		this.data = data;
	}
	public Object[][] getData() {
		return data;
	}
	public void addRow(Object[] row){
		Object[][] dataAux = getData();
		int size = getRowCount();
		data = new Object[size++][getColumnCount()];
		int i = 0;
		for(Object[] arr: dataAux){
			data[i] = arr;
			i++;
		}
		data[i] = row;
	}
	public void addRows(Object[][] data){
		setData(data);
		fireTableRowsInserted(0, data.length);
	}
	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}
}
